﻿using System;
using System.Windows.Forms;
using ChinaDynastyTours.Controls;
using ChinaDynastyTours.Helpers;

namespace ChinaDynastyTours.Views
{
    public partial class ProviderSelectedToolForm : Form
    {
        //输入参数
        public ProviderTypeEnum[] _ProviderTypes { get; set; }
        public string _ProviderName { get; set; }
        public string _CityName { get; set; }
        //输出参数
        public string ReturnProviderName { get; set; }
        public string ReturnProviderID { get; set; }
        
        public ProviderSelectedToolForm()
        {
            InitializeComponent();
        }

        private void HotelProviderForm_Load(object sender, EventArgs e)
        {
            tbCityName.Text = _CityName;
            tbProviderName.Text = _ProviderName;

            btnRefresh.PerformClick();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (providerGridView.DataRowCount > 0)
            {
                ReturnProviderID = providerGridView.GetDataRow(providerGridView.FocusedRowHandle)["ProviderID"].ToString();
                ReturnProviderName = providerGridView.GetDataRow(providerGridView.FocusedRowHandle)["ProviderName"].ToString();
            }
        }

        private void hotelProviderGridView_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (e.Clicks == 2)
                btnOk.PerformClick();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            //_CityName = tbCityName.Text;
            //_ProviderName = tbProviderName.Text;

            providerGridControl.DataSource = BaseInfoCtrl.GetProviderData(_ProviderTypes, CN2PYHelper.CapitalCovert(tbCityName.Text), CN2PYHelper.CapitalCovert(tbProviderName.Text));
        }

        private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
                btnRefresh.PerformClick();
        }

        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            btnRefresh.PerformClick();
        }


    }
}
